package com.swfee.qinben.dao;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * @author ddr
 * 
 */
public class DatabaseHelper extends SQLiteOpenHelper {

	public final static String T_LASTLOGIN = "t_lastlogin";
	public final static String T_APP_LOG = "t_app_log";
	public final static String T_SYSTEM_CONFIG = "t_system_config";

	public DatabaseHelper(Context context) {
		super(context, "com_swfee_qinben.db", null, 1);
	}

	@Override
	public void onCreate(SQLiteDatabase sd) {
		try {
			// sd.execSQL("CREATE TABLE IF NOT EXISTS " + T_PASSENGER + "("
			// + "id integer  primary key autoincrement,"
			// + "login_name varchar(30) not null, "
			// + "psg_id_no varchar(20) not null,"
			// + "psg_name varchar(30) not null ,"
			// + "psg_type SMALLINT not null,"
			// + "create_date BIGINT not null,"
			// + "synched SMALLINT not null,"
			// + "by_train SMALLINT not null"
			// + ")");

			sd.execSQL("CREATE TABLE IF NOT EXISTS " + T_LASTLOGIN + "("
					+ "login_name varchar(30) primary key ,"
					+ "login_pwd  varchar(40) not null,"
					+ "login_date BIGINT not null,"
					+ "app_code  varchar(100) not null )");

			sd.execSQL("CREATE TABLE IF NOT EXISTS " + T_APP_LOG + "("
					+ "id integer primary key ," + " open_date BIGINT not null"
					+ ")");
			;

			sd.execSQL("CREATE TABLE IF NOT EXISTS " + T_SYSTEM_CONFIG + "("
					+ "param_name varchar(40) primary key ," 
				    + "param_value varchar(50) not null"
					+ ")");
			;

			// //测试数据
			// ContentValues meData = new ContentValues();
			// meData.put("psg_id_no", "350821198512040421");
			// meData.put("psg_name", "戴德荣");
			// meData.put("psg_type", 1);
			// meData.put("create_date",new Date().getTime());
			// meData.put("synched",0);
			// sd.insert(tableName, null, meData);
			// meData.put("psg_id_no", "222221198512021121");
			// meData.put("psg_name", "刘明");
			// sd.insert(tableName, null, meData);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	@Override
	public void onUpgrade(SQLiteDatabase sd, int oldVer, int newVer) {
		 sd.execSQL("DROP TABLE IF EXISTS  " + T_APP_LOG);
		 sd.execSQL("DROP TABLE IF EXISTS  " + T_LASTLOGIN);
		 sd.execSQL("DROP TABLE IF EXISTS  " + T_SYSTEM_CONFIG);
		 onCreate(sd);
		return;
	}

}
